/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * 2014-08-03     bernard      Add file header.
 */

#include "rtthread.h"
#include "common.h"
#include "malloc.h"

#ifdef RT_USING_HEAP

#ifdef __CC_ARM
/* avoid the heap and heap-using library functions supplied by arm */
#pragma import(__use_no_heap)
#endif

#define size_t uint32_t

void *malloc(size_t n)
{
  void *pdat;
  
  pdat = mymalloc(n);
  
  DBG_PRINT("malloc addr : 0x%08x\n", pdat);
  
  return pdat;
}
RTM_EXPORT(malloc);

void *realloc(void *rmem, size_t newsize)
{
    if(0 == rmem)
    {
        return mymalloc(newsize);
    }
    else
    {
        myfree(rmem);
        return mymalloc(newsize);
    }
}
RTM_EXPORT(realloc);

void *calloc(size_t nelem, size_t elsize)
{
    uint16_t * pdat, *rtn;
    pdat = mymalloc(elsize);
    rtn = pdat;
    elsize >>= 1;
    while(elsize --)
    {
        *pdat = 0;
    }
    return rtn;
}
RTM_EXPORT(calloc);

void free(void *rmem)
{
    myfree(rmem);
	DBG_PRINT("malloc addr : 0x%08x\n", rmem);
}
RTM_EXPORT(free);
#endif
